//产生唯一的图片文件名中间段：DDHHMMSS+序号(从1开始)
package main

import (
	"fmt"
	"sync"
	"time"
)

type UniqObj struct {
	Day    uint8
	Hour   uint8
	Minute uint8
	Second uint8
	Num    uint32
	lock   sync.Mutex
}

func (self *UniqObj) Reset() {
	t := time.Now()
	self.Day = uint8(t.Day())
	self.Hour = uint8(t.Hour())
	self.Minute = uint8(t.Minute())
	self.Second = uint8(t.Second())
	self.Num = 0
}

func (self *UniqObj) GetID() string {
	t := time.Now()
	if uint8(t.Day()) > self.Day {
		self.Reset()
	}
	self.lock.Lock()
	self.Num++
	res := fmt.Sprintf("%02d%02d%02d%02d%d", self.Day, self.Hour, self.Minute, self.Second, self.Num)
	self.lock.Unlock()
	return res
}
